<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Mr.Feng
  Date: 2023/5/26
  Time: 11:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagination.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/jquery.pagination.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-responsive.css"/>

    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/js/pagination.js"></script>
    <script type="text/javascript" charset="UTF-8" src="${pageContext.request.contextPath}/js/my.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.pagination.min.js"></script>
    <script>
        $(function () {
            var cp = parseInt($("#curPage").val());
            var tp = parseInt($("#tolPage").val());
            $("#pagination2").pagination({
                currentPage: cp,
                totalPage: tp,
                isShow: false,
                count: 5,
                prevPageText: "< 上一页",
                nextPageText: "下一页 >",
                callback: function (current) {
                    location.href = '/book/list/' + current;
                }
            });
        });
    </script>
</head>

<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->
<div class="box-header with-border" style="display: inline-block">
    <h3 class="box-title">用户管理</h3>
</div>
<div class="box-body">
    <div class="pull-left">
        <div class="form-group form-inline">
            <div class="btn-group">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#registerModal">新增</button>
            </div>
        </div>
    </div>
    <!--工具栏 数据搜索 -->

    <!-- 数据列表 -->
    <div class="table-box">
        <!-- 数据表格 -->
        <table class="table table-bordered table-hover definewidth m10">
            <thead>
            <tr>
                <th> 用户ID</th>
                <th> 用户姓名</th>
                <th> 用户邮箱</th>
                <th> 用户状态</th>
                <th> 操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageResult.rows}" var="user">
                <tr>
                    <td>${user.id}</td>
                    <td>${user.name}</td>
                    <td>${user.email}</td>
                    <td>
                        <c:if test="${user.status ==0}">使用中</c:if>
                        <c:if test="${user.status ==1}">被禁用</c:if>
                    </td>
                    <td>
                        <c:if test="${user.role=='USER'}">
                            <c:if test="${user.status =='0'}">
                                <button type="button" class="btn btn-success" data-toggle="modal"
                                        data-target="#borrowModal"
                                        onclick="ban(${user.id})"> 禁用
                                </button>
                            </c:if>
                            <c:if test="${user.status =='1'}">
                                <button type="button" class="btn btn-info" onclick="disban(${user.id})">解禁</button>
                            </c:if>
                        </c:if>
                        <c:if test="${user.role=='ADMIN'}">
                            <button type="button" class="btn btn-info" data-toggle="modal"
                                    data-target="#borrowModal" disabled="true"  title="该用户为管理员用户，无法禁用" aria-label="禁用"
                                    onclick="ban(${user.id})"> 禁用
                            </button>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <!--数据表格/-->
        <div class="box-tools pull-right">
            <div class="has-feedback">
                <form action="${pageContext.request.contextPath}/searchreader" method="post">
                    用户名：<input name="name" value="${search.name}">&nbsp;&nbsp;&nbsp;&nbsp;
                    Email：<input name="email" value="${search.email}">&nbsp;&nbsp;&nbsp;&nbsp;
                    账户状态：<%--<input name="press" value="${search.press}">&nbsp&nbsp&nbsp&nbsp--%>
                    <select name="status" >
                        <option value="0"> 正常</option>
                        <option value="1"> 禁用中</option>
                    </select>
                    <input class="btn btn-default" type="submit" value="查询">
                </form>
            </div>
        </div>
        <%--分页插件--%>
        <div id="pagination" class="pagination"></div>
    </div>
    <!--数据列表/-->
</div>
<script>
    /*分页插件展示的总页数*/
    pageargs.total = Math.ceil(${pageResult.total}/pageargs.pagesize);
    /*分页插件当前的页码*/
    pageargs.cur = ${pageNum}
        /*分页插件页码变化时将跳转到的服务器端的路径*/
        pageargs.gourl = "${gourl}"
    /*保存搜索框中的搜索条件，页码变化时携带之前的搜索条件*/
    bookVO.name = "${search.name}"
    bookVO.author = "${search.email}"
    bookVO.press = "${search.id}"
    /*分页效果*/
    pagination(pageargs);
</script>

<!--新增用户-->
<div class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增用户</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- 注册表单 -->
                <form action="${pageContext.request.contextPath}/addUser" method="post">
                    <div class="form-group">
                        <label >邮箱</label>
                        <input type="email" class="form-control" name="email" placeholder="请输入邮箱">
                    </div>
                    <div class="form-group">
                        <label >用户名</label>
                        <input type="text" class="form-control" name="name" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label >密码</label>
                        <input type="password" class="form-control" name = "password" placeholder="请输入密码">
                    </div>
                    <c:if test="${USER_SESSION.role=='ADMIN'}">
                        <label> 用户身份</label>
                        <select name="role">
                            <option value="ADMIN"> 管理员</option>
                            <option value="USER"> 普通用户</option>
                        </select>
                    </c:if>
                    <button type="submit" class="btn btn-primary">注册</button>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>
